package vivek.project.pocketmoney.common.valdiators
{
	import mx.validators.CurrencyValidator;
	import mx.validators.ValidationResult;

	public class AdvancedCurrencyValidator extends CurrencyValidator
	{
		public function AdvancedCurrencyValidator()
		{
			super();
		}
		private const ZeroNotAllowedError:String="Zero is not a valid value";
		private var _zeroValue:Boolean=false;

		public function get zeroAllowed():Boolean
		{
			return _zeroValue;
		}

		public function set zeroAllowed(value:Boolean):void
		{
			_zeroValue=value;
		}

		override protected function doValidation(value:Object):Array
		{
			var results:Array=super.doValidation(value);
			var val:Number=0;
			// Return if there are errors
			// or if the required property is set to false and length is 0.
			if (results.length > 0)
				return results;
			else
			{
				try
				{
					val=new Number(value);
				}
				catch (error:Error)
				{
					val=0;
				}
				if (val == 0 && !_zeroValue)
					results.push(new ValidationResult(true, null, "zeroNotAllowedError", ZeroNotAllowedError));
			}
			return results;
		}
	}
}